home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_emacs.idb / usr / freeware / info / emacs-6.z / emacs-6
Encoding:
GNU Info File  |  1998-10-28  |  48.3 KB  |  1,190 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.63 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Regexps,  Next: Search Case,  Prev: Regexp Search,  Up: Search
  6.  
  7. Syntax of Regular Expressions
  8. =============================
  9.  
  10.    Regular expressions have a syntax in which a few characters are
  11. special constructs and the rest are "ordinary".  An ordinary character
  12. is a simple regular expression which matches that same character and
  13. nothing else.  The special characters are `$', `^', `.', `*', `+', `?',
  14. `[', `]' and `\'.  Any other character appearing in a regular
  15. expression is ordinary, unless a `\' precedes it.
  16.  
  17.    For example, `f' is not a special character, so it is ordinary, and
  18. therefore `f' is a regular expression that matches the string `f' and
  19. no other string.  (It does *not* match the string `ff'.)  Likewise, `o'
  20. is a regular expression that matches only `o'.  (When case distinctions
  21. are being ignored, these regexps also match `F' and `O', but we
  22. consider this a generalization of "the same string", rather than an
  23. exception.)
  24.  
  25.    Any two regular expressions A and B can be concatenated.  The result
  26. is a regular expression which matches a string if A matches some amount
  27. of the beginning of that string and B matches the rest of the string.
  28.  
  29.    As a simple example, we can concatenate the regular expressions `f'
  30. and `o' to get the regular expression `fo', which matches only the
  31. string `fo'.  Still trivial.  To do something nontrivial, you need to
  32. use one of the special characters.  Here is a list of them.
  33.  
  34. `. (Period)'
  35.      is a special character that matches any single character except a
  36.      newline.  Using concatenation, we can make regular expressions
  37.      like `a.b' which matches any three-character string which begins
  38.      with `a' and ends with `b'.
  39.  
  40. `*'
  41.      is not a construct by itself; it is a postfix operator, which
  42.      means to match the preceding regular expression repetitively as
  43.      many times as possible.  Thus, `o*' matches any number of `o's
  44.      (including no `o's).
  45.  
  46.      `*' always applies to the *smallest* possible preceding
  47.      expression.  Thus, `fo*' has a repeating `o', not a repeating
  48.      `fo'.  It matches `f', `fo', `foo', and so on.
  49.  
  50.      The matcher processes a `*' construct by matching, immediately, as
  51.      many repetitions as can be found.  Then it continues with the rest
  52.      of the pattern.  If that fails, backtracking occurs, discarding
  53.      some of the matches of the `*'-modified construct in case that
  54.      makes it possible to match the rest of the pattern.  For example,
  55.      matching `ca*ar' against the string `caaar', the `a*' first tries
  56.      to match all three `a's; but the rest of the pattern is `ar' and
  57.      there is only `r' left to match, so this try fails.  The next
  58.      alternative is for `a*' to match only two `a's.  With this choice,
  59.      the rest of the regexp matches successfully.
  60.  
  61. `+'
  62.      is a postfix character, similar to `*' except that it must match
  63.      the preceding expression at least once.  So, for example, `ca+r'
  64.      matches the strings `car' and `caaaar' but not the string `cr',
  65.      whereas `ca*r' matches all three strings.
  66.  
  67. `?'
  68.      is a postfix character, similar to `*' except that it can match the
  69.      preceding expression either once or not at all.  For example,
  70.      `ca?r' matches `car' or `cr'; nothing else.
  71.  
  72. `[ ... ]'
  73.      is a "character set", which begins with `[' and is terminated by
  74.      `]'.  In the simplest case, the characters between the two
  75.      brackets are what this set can match.
  76.  
  77.      Thus, `[ad]' matches either one `a' or one `d', and `[ad]*'
  78.      matches any string composed of just `a's and `d's (including the
  79.      empty string), from which it follows that `c[ad]*r' matches `cr',
  80.      `car', `cdr', `caddaar', etc.
  81.  
  82.      You can also include character ranges a character set, by writing
  83.      two characters with a `-' between them.  Thus, `[a-z]' matches any
  84.      lower-case letter.  Ranges may be intermixed freely with individual
  85.      characters, as in `[a-z$%.]', which matches any lower case letter
  86.      or `$', `%' or period.
  87.  
  88.      Note that the usual regexp special characters are not special
  89.      inside a character set.  A completely different set of special
  90.      characters exists inside character sets: `]', `-' and `^'.
  91.  
  92.      To include a `]' in a character set, you must make it the first
  93.      character.  For example, `[]a]' matches `]' or `a'.  To include a
  94.      `-', write `-' as the first or last character of the set, or put
  95.      it after a range.  Thus, `[]-]' matches both `]' and `-'.
  96.  
  97.      To include `^', make it other than the first character in the set.
  98.  
  99. `[^ ... ]'
  100.      `[^' begins a "complemented character set", which matches any
  101.      character except the ones specified.  Thus, `[^a-z0-9A-Z]' matches
  102.      all characters *except* letters and digits.
  103.  
  104.      `^' is not special in a character set unless it is the first
  105.      character.  The character following the `^' is treated as if it
  106.      were first (`-' and `]' are not special there).
  107.  
  108.      A complemented character set can match a newline, unless newline is
  109.      mentioned as one of the characters not to match.  This is in
  110.      contrast to the handling of regexps in programs such as `grep'.
  111.  
  112. `^'
  113.      is a special character that matches the empty string, but only at
  114.      the beginning of a line in the text being matched.  Otherwise it
  115.      fails to match anything.  Thus, `^foo' matches a `foo' which
  116.      occurs at the beginning of a line.
  117.  
  118. `$'
  119.      is similar to `^' but matches only at the end of a line.  Thus,
  120.      `xx*$' matches a string of one `x' or more at the end of a line.
  121.  
  122. `\'
  123.      has two functions: it quotes the special characters (including
  124.      `\'), and it introduces additional special constructs.
  125.  
  126.      Because `\' quotes special characters, `\$' is a regular
  127.      expression which matches only `$', and `\[' is a regular
  128.      expression which matches only `[', etc.
  129.  
  130.    Note: for historical compatibility, special characters are treated as
  131. ordinary ones if they are in contexts where their special meanings make
  132. no sense.  For example, `*foo' treats `*' as ordinary since there is no
  133. preceding expression on which the `*' can act.  It is poor practice to
  134. depend on this behavior; better to quote the special character anyway,
  135. regardless of where it appears.
  136.  
  137.    For the most part, `\' followed by any character matches only that
  138. character.  However, there are several exceptions: two-character
  139. sequences starting with `\' which have special meanings.  The second
  140. character in the sequence is always an ordinary character on their own.
  141. Here is a table of `\' constructs.
  142.  
  143. `\|'
  144.      specifies an alternative.  Two regular expressions A and B with
  145.      `\|' in between form an expression that matches anything that
  146.      either A or B matches.
  147.  
  148.      Thus, `foo\|bar' matches either `foo' or `bar' but no other string.
  149.  
  150.      `\|' applies to the largest possible surrounding expressions.
  151.      Only a surrounding `\( ... \)' grouping can limit the scope of
  152.      `\|'.
  153.  
  154.      Full backtracking capability exists to handle multiple uses of
  155.      `\|'.
  156.  
  157. `\( ... \)'
  158.      is a grouping construct that serves three purposes:
  159.  
  160.        1. To enclose a set of `\|' alternatives for other operations.
  161.           Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
  162.  
  163.        2. To enclose a complicated expression for the postfix operators
  164.           `*', `+' and `?' to operate on.  Thus, `ba\(na\)*' matches
  165.           `bananana', etc., with any (zero or more) number of `na'
  166.           strings.
  167.  
  168.        3. To mark a matched substring for future reference.
  169.  
  170.      This last application is not a consequence of the idea of a
  171.      parenthetical grouping; it is a separate feature which is assigned
  172.      as a second meaning to the same `\( ... \)' construct.  In practice
  173.      there is no conflict between the two meanings.  Here is an
  174.      explanation of this feature:
  175.  
  176. `\D'
  177.      after the end of a `\( ... \)' construct, the matcher remembers
  178.      the beginning and end of the text matched by that construct.  Then,
  179.      later on in the regular expression, you can use `\' followed by the
  180.      digit D to mean "match the same text matched the Dth time by the
  181.      `\( ... \)' construct."
  182.  
  183.      The strings matching the first nine `\( ... \)' constructs
  184.      appearing in a regular expression are assigned numbers 1 through 9
  185.      in order that the open-parentheses appear in the regular
  186.      expression.  `\1' through `\9' refer to the text previously
  187.      matched by the corresponding `\( ... \)' construct.
  188.  
  189.      For example, `\(.*\)\1' matches any newline-free string that is
  190.      composed of two identical halves.  The `\(.*\)' matches the first
  191.      half, which may be anything, but the `\1' that follows must match
  192.      the same exact text.
  193.  
  194.      If a particular `\( ... \)' construct matches more than once
  195.      (which can easily happen if it is followed by `*'), only the last
  196.      match is recorded.
  197.  
  198. `\`'
  199.      matches the empty string, provided it is at the beginning of the
  200.      buffer or string being matched against.
  201.  
  202. `\''
  203.      matches the empty string, provided it is at the end of the buffer
  204.      or string being matched against.
  205.  
  206. `\='
  207.      matches the empty string, provided it is at point.
  208.  
  209. `\b'
  210.      matches the empty string, provided it is at the beginning or end
  211.      of a word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a
  212.      separate word.  `\bballs?\b' matches `ball' or `balls' as a
  213.      separate word.
  214.  
  215.      `\b' matches at the beginning or end of the buffer regardless of
  216.      what text appears next to it.
  217.  
  218. `\B'
  219.      matches the empty string, provided it is *not* at the beginning or
  220.      end of a word.
  221.  
  222. `\<'
  223.      matches the empty string, provided it is at the beginning of a
  224.      word.  `\<' matches at the beginning of the buffer only if a
  225.      word-constituent character follows.
  226.  
  227. `\>'
  228.      matches the empty string, provided it is at the end of a word.
  229.      `\>' matches at the end of the buffer only if the contents end with
  230.      a word-constituent character.
  231.  
  232. `\w'
  233.      matches any word-constituent character.  The syntax table
  234.      determines which characters these are.  *Note Syntax::.
  235.  
  236. `\W'
  237.      matches any character that is not a word-constituent.
  238.  
  239. `\sC'
  240.      matches any character whose syntax is C.  Here C is a character
  241.      which represents a syntax code: thus, `w' for word constituent,
  242.      `(' for open-parenthesis, etc.  Represent a character of
  243.      whitespace (which can be a newline) by either `-' or a space
  244.      character.
  245.  
  246. `\SC'
  247.      matches any character whose syntax is not C.
  248.  
  249.    The constructs that pertain to words and syntax are controlled by the
  250. setting of the syntax table (*note Syntax::.).
  251.  
  252.    Here is a complicated regexp, used by Emacs to recognize the end of a
  253. sentence together with any whitespace that follows.  It is given in Lisp
  254. syntax to enable you to distinguish the spaces from the tab characters.
  255. In Lisp syntax, the string constant begins and ends with a
  256. double-quote.  `\"' stands for a double-quote as part of the regexp,
  257. `\\' for a backslash as part of the regexp, `\t' for a tab and `\n' for
  258. a newline.
  259.  
  260.      "[.?!][]\"')]*\\($\\|\t\\|  \\)[ \t\n]*"
  261.  
  262. This contains four parts in succession: a character set matching period,
  263. `?', or `!'; a character set matching close-brackets, quotes, or
  264. parentheses, repeated any number of times; an alternative in
  265. backslash-parentheses that matches end-of-line, a tab, or two spaces;
  266. and a character set matching whitespace characters, repeated any number
  267. of times.
  268.  
  269.    To enter the same regexp interactively, you would type TAB to enter
  270. a tab, and `C-q C-j' to enter a newline.  You would also type single
  271. backslashes as themselves, instead of doubling them for Lisp syntax.
  272.  
  273. 
  274. File: emacs,  Node: Search Case,  Next: Replace,  Prev: Regexps,  Up: Search
  275.  
  276. Searching and Case
  277. ==================
  278.  
  279.    Incremental searches in Emacs normally ignore the case of the text
  280. they are searching through, if you specify the text in lower case.
  281. Thus, if you specify searching for `foo', then `Foo' and `foo' are also
  282. considered a match.  Regexps, and in particular character sets, are
  283. included: `[ab]' would match `a' or `A' or `b' or `B'.
  284.  
  285.    An upper-case letter in the incremental search string makes the
  286. search case-sensitive.  Thus, searching for `Foo' does not find `foo'
  287. or `FOO'.  This applies to regular expression search as well as to
  288. string search.  The effect ceases if you delete the upper-case letter
  289. from the search string.
  290.  
  291.    If you set the variable `case-fold-search' to `nil', then all
  292. letters must match exactly, including case.  This is a per-buffer
  293. variable; altering the variable affects only the current buffer, but
  294. there is a default value which you can change as well.  *Note Locals::.
  295. This variable applies to nonincremental searches also, including those
  296. performed by the replace commands (*note Replace::.).
  297.  
  298. 
  299. File: emacs,  Node: Replace,  Next: Other Repeating Search,  Prev: Search Case,  Up: Search
  300.  
  301. Replacement Commands
  302. ====================
  303.  
  304.    Global search-and-replace operations are not needed as often in Emacs
  305. as they are in other editors(1), but they are available.  In addition
  306. to the simple `M-x replace-string' command which is like that found in
  307. most editors, there is a `M-x query-replace' command which asks you, for
  308. each occurrence of the pattern, whether to replace it.
  309.  
  310.    The replace commands all replace one string (or regexp) with one
  311. replacement string.  It is possible to perform several replacements in
  312. parallel using the command `expand-region-abbrevs'.  *Note Expanding
  313. Abbrevs::.
  314.  
  315. * Menu:
  316.  
  317. * Unconditional Replace::  Replacing all matches for a string.
  318. * Regexp Replace::         Replacing all matches for a regexp.
  319. * Replacement and Case::   How replacements preserve case of letters.
  320. * Query Replace::          How to use querying.
  321.  
  322.    ---------- Footnotes ----------
  323.  
  324.    (1)  In some editors, search-and-replace operations are the only
  325. convenient way to make a single change in the text.
  326.  
  327. 
  328. File: emacs,  Node: Unconditional Replace,  Next: Regexp Replace,  Prev: Replace,  Up: Replace
  329.  
  330. Unconditional Replacement
  331. -------------------------
  332.  
  333. `M-x replace-string RET STRING RET NEWSTRING RET'
  334.      Replace every occurrence of STRING with NEWSTRING.
  335.  
  336. `M-x replace-regexp RET REGEXP RET NEWSTRING RET'
  337.      Replace every match for REGEXP with NEWSTRING.
  338.  
  339.    To replace every instance of `foo' after point with `bar', use the
  340. command `M-x replace-string' with the two arguments `foo' and `bar'.
  341. Replacement happens only in the text after point, so if you want to
  342. cover the whole buffer you must go to the beginning first.  All
  343. occurrences up to the end of the buffer are replaced; to limit
  344. replacement to part of the buffer, narrow to that part of the buffer
  345. before doing the replacement (*note Narrowing::.).
  346.  
  347.    When `replace-string' exits, it leaves point at the last occurrence
  348. replaced.  It sets the mark to the prior position of point (where the
  349. `replace-string' command was issued); use `C-u C-SPC' to move back
  350. there.
  351.  
  352.    A numeric argument restricts replacement to matches that are
  353. surrounded by word boundaries.  The argument's value doesn't matter.
  354.  
  355. 
  356. File: emacs,  Node: Regexp Replace,  Next: Replacement and Case,  Prev: Unconditional Replace,  Up: Replace
  357.  
  358. Regexp Replacement
  359. ------------------
  360.  
  361.    The `M-x replace-string' command replaces exact matches for a single
  362. string.  The similar command `M-x replace-regexp' replaces any match
  363. for a specified pattern.
  364.  
  365.    In `replace-regexp', the NEWSTRING need not be constant: it can
  366. refer to all or part of what is matched by the REGEXP.  `\&' in
  367. NEWSTRING stands for the entire match being replaced.  `\D' in
  368. NEWSTRING, where D is a digit, stands for whatever matched the Dth
  369. parenthesized grouping in REGEXP.  To include a `\' in the text to
  370. replace with, you must enter `\\'.  For example,
  371.  
  372.      M-x replace-regexp RET c[ad]+r RET \&-safe RET
  373.  
  374. replaces (for example) `cadr' with `cadr-safe' and `cddr' with
  375. `cddr-safe'.
  376.  
  377.      M-x replace-regexp RET \(c[ad]+r\)-safe RET \1 RET
  378.  
  379. performs the inverse transformation.
  380.  
  381. 
  382. File: emacs,  Node: Replacement and Case,  Next: Query Replace,  Prev: Regexp Replace,  Up: Replace
  383.  
  384. Replace Commands and Case
  385. -------------------------
  386.  
  387.    If the arguments to a replace command are in lower case, it preserves
  388. case when it makes a replacement.  Thus, the command
  389.  
  390.      M-x replace-string RET foo RET bar RET
  391.  
  392. replaces a lower case `foo' with a lower case `bar', an all-caps `FOO'
  393. with `BAR', and a capitalized `Foo' with `Bar'.  (These three
  394. alternatives-lower case, all caps, and capitalized, are the only ones
  395. that `replace-string' can distinguish.)
  396.  
  397.    If upper case letters are used in the second argument, they remain
  398. upper case every time that argument is inserted.  If upper case letters
  399. are used in the first argument, the second argument is always
  400. substituted exactly as given, with no case conversion.  Likewise, if the
  401. variable `case-replace' is set to `nil', replacement is done without
  402. case conversion.  If `case-fold-search' is set to `nil', case is
  403. significant in matching occurrences of `foo' to replace; this also
  404. inhibits case conversion of the replacement string.
  405.  
  406. 
  407. File: emacs,  Node: Query Replace,  Prev: Replacement and Case,  Up: Replace
  408.  
  409. Query Replace
  410. -------------
  411.  
  412. `M-% STRING RET NEWSTRING RET'
  413. `M-x query-replace RET STRING RET NEWSTRING RET'
  414.      Replace some occurrences of STRING with NEWSTRING.
  415.  
  416. `M-x query-replace-regexp RET REGEXP RET NEWSTRING RET'
  417.      Replace some matches for REGEXP with NEWSTRING.
  418.  
  419.    If you want to change only some of the occurrences of `foo' to
  420. `bar', not all of them, then you cannot use an ordinary
  421. `replace-string'.  Instead, use `M-%' (`query-replace').  This command
  422. finds occurrences of `foo' one by one, displays each occurrence and
  423. asks you whether to replace it.  A numeric argument to `query-replace'
  424. tells it to consider only occurrences that are bounded by
  425. word-delimiter characters.  This preserves case, just like
  426. `replace-string', provided `case-replace' is non-`nil', as it normally
  427. is.
  428.  
  429.    Aside from querying, `query-replace' works just like
  430. `replace-string', and `query-replace-regexp' works just like
  431. `replace-regexp'.  The shortest way to type this command name is `M-x
  432. que SPC SPC SPC RET'.
  433.  
  434.    The things you can type when you are shown an occurrence of STRING
  435. or a match for REGEXP are:
  436.  
  437. `SPC'
  438.      to replace the occurrence with NEWSTRING.
  439.  
  440. `DEL'
  441.      to skip to the next occurrence without replacing this one.
  442.  
  443. `, (Comma)'
  444.      to replace this occurrence and display the result.  You are then
  445.      asked for another input character to say what to do next.  Since
  446.      the replacement has already been made, DEL and SPC are equivalent
  447.      in this situation; both move to the next occurrence.
  448.  
  449.      You could type `C-r' at this point (see below) to alter the
  450.      replaced text.  You could also type `C-x u' to undo the
  451.      replacement; this exits the `query-replace', so if you want to do
  452.      further replacement you must use `C-x ESC ESC RET' to restart
  453.      (*note Repetition::.).
  454.  
  455. `RET'
  456.      to exit without doing any more replacements.
  457.  
  458. `. (Period)'
  459.      to replace this occurrence and then exit without searching for more
  460.      occurrences.
  461.  
  462. `!'
  463.      to replace all remaining occurrences without asking again.
  464.  
  465. `^'
  466.      to go back to the position of the previous occurrence (or what
  467.      used to be an occurrence), in case you changed it by mistake.
  468.      This works by popping the mark ring.  Only one `^' in a row is
  469.      meaningful, because only one previous replacement position is kept
  470.      during `query-replace'.
  471.  
  472. `C-r'
  473.      to enter a recursive editing level, in case the occurrence needs
  474.      to be edited rather than just replaced with NEWSTRING.  When you
  475.      are done, exit the recursive editing level with `C-M-c' to proceed
  476.      to the next occurrence.  *Note Recursive Edit::.
  477.  
  478. `C-w'
  479.      to delete the occurrence, and then enter a recursive editing level
  480.      as in `C-r'.  Use the recursive edit to insert text to replace the
  481.      deleted occurrence of STRING.  When done, exit the recursive
  482.      editing level with `C-M-c' to proceed to the next occurrence.
  483.  
  484. `C-l'
  485.      to redisplay the screen.  Then you must type another character to
  486.      specify what to do with this occurrence.
  487.  
  488. `C-h'
  489.      to display a message summarizing these options.  Then you must type
  490.      another character to specify what to do with this occurrence.
  491.  
  492.    Some other characters are aliases for the ones listed above: `y',
  493. `n' and `q' are equivalent to SPC, DEL and RET.
  494.  
  495.    Aside from this, any other character exits the `query-replace', and
  496. is then reread as part of a key sequence.  Thus, if you type `C-k', it
  497. exits the `query-replace' and then kills to end of line.
  498.  
  499.    To restart a `query-replace' once it is exited, use `C-x ESC ESC',
  500. which repeats the `query-replace' because it used the minibuffer to
  501. read its arguments.  *Note C-x ESC ESC: Repetition.
  502.  
  503.    See also *Note Transforming File Names::, for Dired commands to
  504. rename, copy, or link files by replacing regexp matches in file names.
  505.  
  506. 
  507. File: emacs,  Node: Other Repeating Search,  Prev: Replace,  Up: Search
  508.  
  509. Other Search-and-Loop Commands
  510. ==============================
  511.  
  512.    Here are some other commands that find matches for a regular
  513. expression.  They all operate from point to the end of the buffer.
  514.  
  515. `M-x occur RET REGEXP RET'
  516.      Display a list showing each line in the buffer that contains a
  517.      match for REGEXP.  A numeric argument specifies the number of
  518.      context lines to print before and after each matching line; the
  519.      default is none.  To limit the search to part of the buffer,
  520.      narrow to that part (*note Narrowing::.).
  521.  
  522.      The buffer `*Occur*' containing the output serves as a menu for
  523.      finding the occurrences in their original context.  Click `Mouse-2'
  524.      on an occurrence listed in `*Occur*', or position point there and
  525.      type RET; this switches to the buffer that was searched and moves
  526.      point to the original of the chosen occurrence.
  527.  
  528. `M-x list-matching-lines'
  529.      Synonym for `M-x occur'.
  530.  
  531. `M-x count-matches RET REGEXP RET'
  532.      Print the number of matches for REGEXP after point.
  533.  
  534. `M-x flush-lines RET REGEXP RET'
  535.      Delete each line that follows point and contains a match for
  536.      REGEXP.
  537.  
  538. `M-x keep-lines RET REGEXP RET'
  539.      Delete each line that follows point and *does not* contain a match
  540.      for REGEXP.
  541.  
  542. 
  543. File: emacs,  Node: Fixit,  Next: Files,  Prev: Search,  Up: Top
  544.  
  545. Commands for Fixing Typos
  546. *************************
  547.  
  548.    In this chapter we describe the commands that are especially useful
  549. for the times when you catch a mistake in your text just after you have
  550. made it, or change your mind while composing text on the fly.
  551.  
  552.    The most fundamental command for correcting erroneous editing is the
  553. undo command, `C-x u' or `C-_'.  This command undoes a single command
  554. (usually), a part of a command (in the case of `query-replace'), or
  555. several consecutive self-inserting characters.  Consecutive repetitions
  556. of `C-_' or `C-x u' undo earlier and earlier changes, back to the limit
  557. of the undo information available.  *Note Undo::, for for more
  558. information.
  559.  
  560. * Menu:
  561.  
  562. * Kill Errors:: Commands to kill a batch of recently entered text.
  563. * Transpose::   Exchanging two characters, words, lines, lists...
  564. * Fixing Case:: Correcting case of last word entered.
  565. * Spelling::    Apply spelling checker to a word, or a whole file.
  566.  
  567. 
  568. File: emacs,  Node: Kill Errors,  Next: Transpose,  Up: Fixit
  569.  
  570. Killing Your Mistakes
  571. =====================
  572.  
  573. `DEL'
  574.      Delete last character (`delete-backward-char').
  575.  
  576. `M-DEL'
  577.      Kill last word (`backward-kill-word').
  578.  
  579. `C-x DEL'
  580.      Kill to beginning of sentence (`backward-kill-sentence').
  581.  
  582.    The DEL character (`delete-backward-char') is the most important
  583. correction command.  It deletes the character before point.  When DEL
  584. follows a self-inserting character command, you can think of it as
  585. canceling that command.  However, avoid the mistake of thinking of DEL
  586. as a general way to cancel a command!
  587.  
  588.    When your mistake is longer than a couple of characters, it might be
  589. more convenient to use `M-DEL' or `C-x DEL'.  `M-DEL' kills back to the
  590. start of the last word, and `C-x DEL' kills back to the start of the
  591. last sentence.  `C-x DEL' is particularly useful when you change your
  592. mind about the phrasing of the text you are writing.  `M-DEL' and `C-x
  593. DEL' save the killed text for `C-y' and `M-y' to retrieve.  *Note
  594. Yanking::.
  595.  
  596.    `M-DEL' is often useful even when you have typed only a few
  597. characters wrong, if you know you are confused in your typing and aren't
  598. sure exactly what you typed.  At such a time, you cannot correct with
  599. DEL except by looking at the screen to see what you did.  Often it
  600. requires less thought to kill the whole word and start again.
  601.  
  602. 
  603. File: emacs,  Node: Transpose,  Next: Fixing Case,  Prev: Kill Errors,  Up: Fixit
  604.  
  605. Transposing Text
  606. ================
  607.  
  608. `C-t'
  609.      Transpose two characters (`transpose-chars').
  610.  
  611. `M-t'
  612.      Transpose two words (`transpose-words').
  613.  
  614. `C-M-t'
  615.      Transpose two balanced expressions (`transpose-sexps').
  616.  
  617. `C-x C-t'
  618.      Transpose two lines (`transpose-lines').
  619.  
  620.    The common error of transposing two characters can be fixed, when
  621. they are adjacent, with the `C-t' command (`transpose-chars').
  622. Normally, `C-t' transposes the two characters on either side of point.
  623. When given at the end of a line, rather than transposing the last
  624. character of the line with the newline, which would be useless, `C-t'
  625. transposes the last two characters on the line.  So, if you catch your
  626. transposition error right away, you can fix it with just a `C-t'.  If
  627. you don't catch it so fast, you must move the cursor back to between
  628. the two transposed characters.  If you transposed a space with the last
  629. character of the word before it, the word motion commands are a good
  630. way of getting there.  Otherwise, a reverse search (`C-r') is often the
  631. best way.  *Note Search::.
  632.  
  633.    `M-t' (`transpose-words') transposes the word before point with the
  634. word after point.  It moves point forward over a word, dragging the
  635. word preceding or containing point forward as well.  The punctuation
  636. characters between the words do not move.  For example, `FOO, BAR'
  637. transposes into `BAR, FOO' rather than `BAR FOO,'.
  638.  
  639.    `C-M-t' (`transpose-sexps') is a similar command for transposing two
  640. expressions (*note Lists::.), and `C-x C-t' (`transpose-lines')
  641. exchanges lines.  They work like `M-t' except in determining the
  642. division of the text into syntactic units.
  643.  
  644.    A numeric argument to a transpose command serves as a repeat count:
  645. it tells the transpose command to move the character (word, sexp, line)
  646. before or containing point across several other characters (words,
  647. sexps, lines).  For example, `C-u 3 C-t' moves the character before
  648. point forward across three other characters.  It would change
  649. `f-!-oobar' into `oobf-!-ar'.  This is equivalent to repeating `C-t'
  650. three times.  `C-u - 4 M-t' moves the word before point backward across
  651. four words.  `C-u - C-M-t' would cancel the effect of plain `C-M-t'.
  652.  
  653.    A numeric argument of zero is assigned a special meaning (because
  654. otherwise a command with a repeat count of zero would do nothing): to
  655. transpose the character (word, sexp, line) ending after point with the
  656. one ending after the mark.
  657.  
  658. 
  659. File: emacs,  Node: Fixing Case,  Next: Spelling,  Prev: Transpose,  Up: Fixit
  660.  
  661. Case Conversion
  662. ===============
  663.  
  664. `M-- M-l'
  665.      Convert last word to lower case.  Note `Meta--' is Meta-minus.
  666.  
  667. `M-- M-u'
  668.      Convert last word to all upper case.
  669.  
  670. `M-- M-c'
  671.      Convert last word to lower case with capital initial.
  672.  
  673.    A very common error is to type words in the wrong case.  Because of
  674. this, the word case-conversion commands `M-l', `M-u' and `M-c' have a
  675. special feature when used with a negative argument: they do not move the
  676. cursor.  As soon as you see you have mistyped the last word, you can
  677. simply case-convert it and go on typing.  *Note Case::.
  678.  
  679. 
  680. File: emacs,  Node: Spelling,  Prev: Fixing Case,  Up: Fixit
  681.  
  682. Checking and Correcting Spelling
  683. ================================
  684.  
  685.    This section describes the commands to check the spelling of a single
  686. word or of a portion of a buffer.  These commands work with the spelling
  687. checker program Ispell, which is not part of Emacs.  *Note Ispell: (The
  688. Ispell Manual)Top.
  689.  
  690. `M-$'
  691.      Check and correct spelling of word at point (`ispell-word').
  692.  
  693. `M-TAB'
  694.      Complete the word before point based on the spelling dictionary
  695.      (`ispell-complete-word').
  696.  
  697. `M-x ispell-buffer'
  698.      Check and correct spelling of each word in the buffer.
  699.  
  700. `M-x ispell-region'
  701.      Check and correct spelling of each word in the region.
  702.  
  703. `M-x ispell-message'
  704.      Check and correct spelling of each word in a draft mail message,
  705.      excluding cited material.
  706.  
  707. `M-x ispell-change-dictionary RET DICT RET'
  708.      Restart the ispell process, using DICT as the dictionary.
  709.  
  710. `M-x ispell-kill-ispell'
  711.      Kill the Ispell subprocess.
  712.  
  713.    To check the spelling of the word around or next to point, and
  714. optionally correct it as well, use the command `M-$' (`ispell-word').
  715. If the word is not correct, the command offers you various alternatives
  716. for what to do about it.
  717.  
  718.    To check the entire current buffer, use `M-x ispell-buffer'.  Use
  719. `M-x ispell-region' to check just the current region.  To check
  720. spelling in an email message you are writing, use `M-x ispell-message';
  721. that checks the whole buffer, but does not check material that is
  722. indented or appears to be cited from other messages.
  723.  
  724.    Each time these commands encounter an incorrect word, they ask you
  725. what to do.  It displays a list of alternatives, usually including
  726. several "near-misses"--words that are close to the word being checked.
  727. Then you must type a character.  Here are the valid responses:
  728.  
  729. `SPC'
  730.      Skip this word--continue to consider it incorrect, but don't
  731.      change it here.
  732.  
  733. `r NEW RET'
  734.      Replace the word (just this time) with NEW.
  735.  
  736. `R NEW RET'
  737.      Replace the word with NEW, and do a `query-replace' so you can
  738.      replace it elsewhere in the buffer if you wish.
  739.  
  740. `DIGIT'
  741.      Replace the word (just this time) with one of the displayed
  742.      near-misses.  Each near-miss is listed with a digit; type that
  743.      digit to select it.
  744.  
  745. `a'
  746.      Accept the incorrect word--treat it as correct, but only in this
  747.      editing session.
  748.  
  749. `A'
  750.      Accept the incorrect word--treat it as correct, but only in this
  751.      editing session and for this buffer.
  752.  
  753. `i'
  754.      Insert this word in your private dictionary file so that Ispell
  755.      will consider it correct it from now on, even in future sessions.
  756.  
  757. `u'
  758.      Insert a lower-case version of this word in your private dictionary
  759.      file.
  760.  
  761. `m'
  762.      Like `i', but you can also specify dictionary completion
  763.      information.
  764.  
  765. `l WORD RET'
  766.      Look in the dictionary for words that match WORD.  These words
  767.      become the new list of "near-misses"; you can select one of them to
  768.      replace with by typing a digit.  You can use `*' in WORD as a
  769.      wildcard.
  770.  
  771. `C-g'
  772.      Quit interactive spell checking.  You can restart it again
  773.      afterward with `C-u M-$'.
  774.  
  775. `X'
  776.      Same as `C-g'.
  777.  
  778. `x'
  779.      Quit interactive spell checking and move point back to where it was
  780.      when you started spell checking.
  781.  
  782. `q'
  783.      Quit interactive spell checking and kill the Ispell subprocess.
  784.  
  785. `C-l'
  786.      Refresh the screen.
  787.  
  788. `C-z'
  789.      This key has its normal command meaning (suspend Emacs or iconify
  790.      this frame).
  791.  
  792.    The command `ispell-complete-word', which is bound to the key
  793. `M-TAB' in Text mode and related modes, shows a list of completions
  794. based on spelling correction.  Insert the beginning of a word, and then
  795. type `M-TAB'; the command displays a completion list window.  To choose
  796. one of the completions listed, click `Mouse-2' on it, or move the
  797. cursor there in the completions window and type RET.  *Note Text Mode::.
  798.  
  799.    Once started, the Ispell subprocess continues to run (waiting for
  800. something to do), so that subsequent spell checking commands complete
  801. more quickly.  If you want to get rid of the Ispell process, use `M-x
  802. ispell-kill-ispell'.  This is not usually necessary, since the process
  803. uses no time except when you do spelling correction.
  804.  
  805.    Ispell uses two dictionaries: the standard dictionary and your
  806. private dictionary.  The variable `ispell-dictionary' specifies the file
  807. name of the standard dictionary to use.  A value of `nil' says to use
  808. the default dictionary.  The command `M-x ispell-change-dictionary'
  809. sets this variable and then restarts the Ispell subprocess, so that it
  810. will use a different dictionary.
  811.  
  812. 
  813. File: emacs,  Node: Files,  Next: Buffers,  Prev: Fixit,  Up: Top
  814.  
  815. File Handling
  816. *************
  817.  
  818.    The operating system stores data permanently in named "files".  So
  819. most of the text you edit with Emacs comes from a file and is ultimately
  820. stored in a file.
  821.  
  822.    To edit a file, you must tell Emacs to read the file and prepare a
  823. buffer containing a copy of the file's text.  This is called "visiting"
  824. the file.  Editing commands apply directly to text in the buffer; that
  825. is, to the copy inside Emacs.  Your changes appear in the file itself
  826. only when you "save" the buffer back into the file.
  827.  
  828.    In addition to visiting and saving files, Emacs can delete, copy,
  829. rename, and append to files, keep multiple versions of them, and operate
  830. on file directories.
  831.  
  832. * Menu:
  833.  
  834. * File Names::       How to type and edit file name arguments.
  835. * Visiting::         Visiting a file prepares Emacs to edit the file.
  836. * Saving::           Saving makes your changes permanent.
  837. * Reverting::        Reverting cancels all the changes not saved.
  838. * Auto Save::        Auto Save periodically protects against loss of data.
  839. * File Aliases::     Handling multiple names for one file.
  840. * Version Control::  Version control systems (RCS, CVS and SCCS).
  841. * Directories::      Creating, deleting and listing file directories.
  842. * Comparing Files::  Finding where two files differ.
  843. * Misc File Ops::    Other things you can do on files.
  844. * Compressed Files:: Accessing compressed files.
  845.  
  846. 
  847. File: emacs,  Node: File Names,  Next: Visiting,  Up: Files
  848.  
  849. File Names
  850. ==========
  851.  
  852.    Most Emacs commands that operate on a file require you to specify the
  853. file name.  (Saving and reverting are exceptions; the buffer knows which
  854. file name to use for them.)  You enter the file name using the
  855. minibuffer (*note Minibuffer::.).  "Completion" is available, to make
  856. it easier to specify long file names.  *Note Completion::.
  857.  
  858.    For most operations, there is a "default file name" which is used if
  859. you type just RET to enter an empty argument.  Normally the default
  860. file name is the name of the file visited in the current buffer; this
  861. makes it easy to operate on that file with any of the Emacs file
  862. commands.
  863.  
  864.    Each buffer has a default directory, normally the same as the
  865. directory of the file visited in that buffer.  When you enter a file
  866. name without a directory, the default directory is used.  If you specify
  867. a directory in a relative fashion, with a name that does not start with
  868. a slash, it is interpreted with respect to the default directory.  The
  869. default directory is kept in the variable `default-directory', which
  870. has a separate value in every buffer.
  871.  
  872.    For example, if the default file name is `/u/rms/gnu/gnu.tasks' then
  873. the default directory is `/u/rms/gnu/'.  If you type just `foo', which
  874. does not specify a directory, it is short for `/u/rms/gnu/foo'.
  875. `../.login' would stand for `/u/rms/.login'.  `new/foo' would stand for
  876. the file name `/u/rms/gnu/new/foo'.
  877.  
  878.    The command `M-x pwd' prints the current buffer's default directory,
  879. and the command `M-x cd' sets it (to a value read using the
  880. minibuffer).  A buffer's default directory changes only when the `cd'
  881. command is used.  A file-visiting buffer's default directory is
  882. initialized to the directory of the file that is visited there.  If you
  883. create a buffer with `C-x b', its default directory is copied from that
  884. of the buffer that was current at the time.
  885.  
  886.    The default directory actually appears in the minibuffer when the
  887. minibuffer becomes active to read a file name.  This serves two
  888. purposes: it *shows* you what the default is, so that you can type a
  889. relative file name and know with certainty what it will mean, and it
  890. allows you to *edit* the default to specify a different directory.
  891. This insertion of the default directory is inhibited if the variable
  892. `insert-default-directory' is set to `nil'.
  893.  
  894.    Note that it is legitimate to type an absolute file name after you
  895. enter the minibuffer, ignoring the presence of the default directory
  896. name as part of the text.  The final minibuffer contents may look
  897. invalid, but that is not so.  For example, if the minibuffer starts out
  898. with `/usr/tmp/' and you add `/x1/rms/foo', you get
  899. `/usr/tmp//x1/rms/foo'; but Emacs ignores everything through the first
  900. slash in the double slash; the result is `/x1/rms/foo'.  *Note
  901. Minibuffer File::.
  902.  
  903.    You can refer to files on other machines using a special file name
  904. syntax:
  905.  
  906.      /HOST:FILENAME
  907.      /USER@HOST:FILENAME
  908.  
  909. When you do this, Emacs uses the FTP program to read and write files on
  910. the specified host.  It logs in through FTP using your user name or the
  911. name USER.  It may ask you for a password from time to time; this is
  912. used for logging in on HOST.
  913.  
  914.    You can turn off the FTP file name feature by setting the variable
  915. `file-name-handler-alist' to `nil'.
  916.  
  917.    `$' in a file name is used to substitute environment variables.  For
  918. example, if you have used the shell command `export FOO=rms/hacks' to
  919. set up an environment variable named `FOO', then you can use
  920. `/u/$FOO/test.c' or `/u/${FOO}/test.c' as an abbreviation for
  921. `/u/rms/hacks/test.c'.  The environment variable name consists of all
  922. the alphanumeric characters after the `$'; alternatively, it may be
  923. enclosed in braces after the `$'.  Note that shell commands to set
  924. environment variables affect Emacs only if done before Emacs is started.
  925.  
  926.    To access a file with `$' in its name, type `$$'.  This pair is
  927. converted to a single `$' at the same time as variable substitution is
  928. performed for single `$'.  The Lisp function that performs the
  929. substitution is called `substitute-in-file-name'.  The substitution is
  930. performed only on file names read as such using the minibuffer.
  931.  
  932. 
  933. File: emacs,  Node: Visiting,  Next: Saving,  Prev: File Names,  Up: Files
  934.  
  935. Visiting Files
  936. ==============
  937.  
  938. `C-x C-f'
  939.      Visit a file (`find-file').
  940.  
  941. `C-x C-r'
  942.      Visit a file for viewing, without allowing changes to it
  943.      (`find-file-read-only').
  944.  
  945. `C-x C-v'
  946.      Visit a different file instead of the one visited last
  947.      (`find-alternate-file').
  948.  
  949. `C-x 4 C-f'
  950.      Visit a file, in another window (`find-file-other-window').  Don't
  951.      change the selected window.
  952.  
  953. `C-x 5 C-f'
  954.      Visit a file, in a new frame (`find-file-other-frame').  Don't
  955.      change the selected frame.
  956.  
  957. `M-x auto-compression-mode'
  958.      Toggle automatic uncompression and recompression for compressed
  959.      files.
  960.  
  961.    "Visiting" a file means copying its contents into an Emacs buffer so
  962. you can edit them.  Emacs makes a new buffer for each file that you
  963. visit.  We say that this buffer is visiting the file that it was created
  964. to hold.  Emacs constructs the buffer name from the file name by
  965. throwing away the directory, keeping just the name proper.  For example,
  966. a file named `/usr/rms/emacs.tex' would get a buffer named `emacs.tex'.
  967. If there is already a buffer with that name, a unique name is
  968. constructed by appending `<2>', `<3>', or so on, using the lowest
  969. number that makes a name that is not already in use.
  970.  
  971.    Each window's mode line shows the name of the buffer that is being
  972. displayed in that window, so you can always tell what buffer you are
  973. editing.
  974.  
  975.    The changes you make with editing commands are made in the Emacs
  976. buffer.  They do not take effect in the file that you visited, or any
  977. place permanent, until you "save" the buffer.  Saving the buffer means
  978. that Emacs writes the current contents of the buffer into its visited
  979. file.  *Note Saving::.
  980.  
  981.    If a buffer contains changes that have not been saved, we say the
  982. buffer is "modified".  This is important because it implies that some
  983. changes will be lost if the buffer is not saved.  The mode line
  984. displays two stars near the left margin to indicate that the buffer is
  985. modified.
  986.  
  987.    To visit a file, use the command `C-x C-f' (`find-file').  Follow
  988. the command with the name of the file you wish to visit, terminated by a
  989. RET.
  990.  
  991.    The file name is read using the minibuffer (*note Minibuffer::.),
  992. with defaulting and completion in the standard manner (*note File
  993. Names::.).  While in the minibuffer, you can abort `C-x C-f' by typing
  994. `C-g'.
  995.  
  996.    Your confirmation that `C-x C-f' has completed successfully is the
  997. appearance of new text on the screen and a new buffer name in the mode
  998. line.  If the specified file does not exist and could not be created, or
  999. cannot be read, then you get an error, with an error message displayed
  1000. in the echo area.
  1001.  
  1002.    If you visit a file that is already in Emacs, `C-x C-f' does not make
  1003. another copy.  It selects the existing buffer containing that file.
  1004. However, before doing so, it checks that the file itself has not changed
  1005. since you visited or saved it last.  If the file has changed, a warning
  1006. message is printed.  *Note Simultaneous Editing: Interlocking.
  1007.  
  1008.    What if you want to create a new file?  Just visit it.  Emacs prints
  1009. `(New File)' in the echo area, but in other respects behaves as if you
  1010. had visited an existing empty file.  If you make any changes and save
  1011. them, the file is created.
  1012.  
  1013.    If the file you specify is actually a directory, `C-x C-f' invokes
  1014. Dired, the Emacs directory browser so that you can "edit" the contents
  1015. of the directory (*note Dired::.).  Dired is a convenient way to delete,
  1016. look at, or operate on the files in the directory.  However, if the
  1017. variable `find-file-run-dired' is `nil', then it is an error to try to
  1018. visit a directory.
  1019.  
  1020.    If you visit a file that the operating system won't let you modify,
  1021. Emacs makes the buffer read-only, so that you won't go ahead and make
  1022. changes that you'll have trouble saving afterward.  You can make the
  1023. buffer writable with `C-x C-q' (`vc-toggle-read-only').  *Note Misc
  1024. Buffer::.
  1025.  
  1026.    Occasionally you might want to visit a file as read-only in order to
  1027. protect yourself from entering changes accidentally; do so by visiting
  1028. the file with the command `C-x C-r' (`find-file-read-only').
  1029.  
  1030.    If you visit a nonexistent file unintentionally (because you typed
  1031. the wrong file name), use the `C-x C-v' command (`find-alternate-file')
  1032. to visit the file you really wanted.  `C-x C-v' is similar to `C-x
  1033. C-f', but it kills the current buffer (after first offering to save it
  1034. if it is modified).  When it reads the file name to visit, it inserts
  1035. the entire default file name in the buffer, with point just after the
  1036. directory part; this is convenient if you made a slight error in typing
  1037. the name.
  1038.  
  1039.    `C-x 4 f' (`find-file-other-window') is like `C-x C-f' except that
  1040. the buffer containing the specified file is selected in another window.
  1041. The window that was selected before `C-x 4 f' continues to show the
  1042. same buffer it was already showing.  If this command is used when only
  1043. one window is being displayed, that window is split in two, with one
  1044. window showing the same buffer as before, and the other one showing the
  1045. newly requested file.  *Note Windows::.
  1046.  
  1047.    `C-x 5 f' (`find-file-other-frame') is similar, but opens a new
  1048. frame, or makes visible any existing frame showing the file you seek.
  1049. This feature is available only when you are using a window system.
  1050. *Note Frames::.
  1051.  
  1052.    Two special hook variables allow extensions to modify the operation
  1053. of visiting files.  Visiting a file that does not exist runs the
  1054. functions in the list `find-file-not-found-hooks'; this variable holds
  1055. a list of functions, and the functions are called one by one until one
  1056. of them returns non-`nil'.  Any visiting of a file, whether extant or
  1057. not, expects `find-file-hooks' to contain a list of functions and calls
  1058. them all, one by one.  In both cases the functions receive no
  1059. arguments.  Of these two variables, `find-file-not-found-hooks' takes
  1060. effect first.  These variables are *not* normal hooks, and their names
  1061. end in `-hooks' rather than `-hook' to indicate that fact.  *Note
  1062. Hooks::.
  1063.  
  1064.    The command `M-x auto-compression-mode' toggles a mode in which
  1065. visiting a compressed file automatically uncompresses it.  (Editing the
  1066. file and saving it automatically recompresses it.)
  1067.  
  1068.    There are several ways to specify automatically the major mode for
  1069. editing the file (*note Choosing Modes::.), and to specify local
  1070. variables defined for that file (*note File Variables::.).
  1071.  
  1072. 
  1073. File: emacs,  Node: Saving,  Next: Reverting,  Prev: Visiting,  Up: Files
  1074.  
  1075. Saving Files
  1076. ============
  1077.  
  1078.    "Saving" a buffer in Emacs means writing its contents back into the
  1079. file that was visited in the buffer.
  1080.  
  1081. `C-x C-s'
  1082.      Save the current buffer in its visited file (`save-buffer').
  1083.  
  1084. `C-x s'
  1085.      Save any or all buffers in their visited files
  1086.      (`save-some-buffers').
  1087.  
  1088. `M-~'
  1089.      Forget that the current buffer has been changed (`not-modified').
  1090.  
  1091. `C-x C-w'
  1092.      Save the current buffer in a specified file (`write-file').
  1093.  
  1094. `M-x set-visited-file-name'
  1095.      Change file the name under which the current buffer will be saved.
  1096.  
  1097.    When you wish to save the file and make your changes permanent, type
  1098. `C-x C-s' (`save-buffer').  After saving is finished, `C-x C-s'
  1099. displays a message like this:
  1100.  
  1101.      Wrote /u/rms/gnu/gnu.tasks
  1102.  
  1103. If the selected buffer is not modified (no changes have been made in it
  1104. since the buffer was created or last saved), saving is not really done,
  1105. because it would have no effect.  Instead, `C-x C-s' displays a message
  1106. like this in the echo area:
  1107.  
  1108.      (No changes need to be saved)
  1109.  
  1110.    The command `C-x s' (`save-some-buffers') offers to save any or all
  1111. modified buffers.  It asks you what to do with each buffer.  The
  1112. possible responses are analogous to those of `query-replace':
  1113.  
  1114. `y'
  1115.      Save this buffer and ask about the rest of the buffers.
  1116.  
  1117. `n'
  1118.      Don't save this buffer, but ask about the rest of the buffers.
  1119.  
  1120. `!'
  1121.      Save this buffer and all the rest with no more questions.
  1122.  
  1123. `RET'
  1124.      Terminate `save-some-buffers' without any more saving.
  1125.  
  1126. `.'
  1127.      Save this buffer, then exit `save-some-buffers' without even asking
  1128.      about other buffers.
  1129.  
  1130. `C-r'
  1131.      View the buffer that you are currently being asked about.  When
  1132.      you exit View mode, you get back to `save-some-buffers', which
  1133.      asks the question again.
  1134.  
  1135. `C-h'
  1136.      Display a help message about these options.
  1137.  
  1138.    `C-x C-c', the key sequence to exit Emacs, invokes
  1139. `save-some-buffers' and therefore asks the same questions.
  1140.  
  1141.    If you have changed a buffer but you do not want to save the changes,
  1142. you should take some action to prevent it.  Otherwise, each time you use
  1143. `C-x s' or `C-x C-c', you are liable to save this buffer by mistake.
  1144. One thing you can do is type `M-~' (`not-modified'), which clears out
  1145. the indication that the buffer is modified.  If you do this, none of
  1146. the save commands will believe that the buffer needs to be saved.  (`~'
  1147. is often used as a mathematical symbol for `not'; thus `M-~' is `not',
  1148. metafied.)  You could also use `set-visited-file-name' (see below) to
  1149. mark the buffer as visiting a different file name, one which is not in
  1150. use for anything important.  Alternatively, you can cancel all the
  1151. changes made since the file was visited or saved, by reading the text
  1152. from the file again.  This is called "reverting".  *Note Reverting::.
  1153. You could also undo all the changes by repeating the undo command `C-x
  1154. u' until you have undone all the changes; but reverting is easier.
  1155.  
  1156.    `M-x set-visited-file-name' alters the name of the file that the
  1157. current buffer is visiting.  It reads the new file name using the
  1158. minibuffer.  Then it specifies the visited file name and changes the
  1159. buffer name correspondingly (as long as the new name is not in use).
  1160. `set-visited-file-name' does not save the buffer in the newly visited
  1161. file; it just alters the records inside Emacs in case you do save
  1162. later.  It also marks the buffer as "modified" so that `C-x C-s' in
  1163. that buffer *will* save.
  1164.  
  1165.    If you wish to mark the buffer as visiting a different file and save
  1166. it right away, use `C-x C-w' (`write-file').  It is precisely
  1167. equivalent to `set-visited-file-name' followed by `C-x C-s'.  `C-x C-s'
  1168. used on a buffer that is not visiting with a file has the same effect
  1169. as `C-x C-w'; that is, it reads a file name, marks the buffer as
  1170. visiting that file, and saves it there.  The default file name in a
  1171. buffer that is not visiting a file is made by combining the buffer name
  1172. with the buffer's default directory.
  1173.  
  1174.    If Emacs is about to save a file and sees that the date of the latest
  1175. version on disk does not match what Emacs last read or wrote, Emacs
  1176. notifies you of this fact, because it probably indicates a problem
  1177. caused by simultaneous editing and requires your immediate attention.
  1178. *Note Simultaneous Editing: Interlocking.
  1179.  
  1180.    If the variable `require-final-newline' is non-`nil', Emacs puts a
  1181. newline at the end of any file that doesn't already end in one, every
  1182. time a file is saved or written.
  1183.  
  1184. * Menu:
  1185.  
  1186. * Backup::        How Emacs saves the old version of your file.
  1187. * Interlocking::  How Emacs protects against simultaneous editing
  1188.                     of one file by two users.
  1189.  
  1190.